package com.ontheroad.device.model;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ontheroad.utils.JsonUtils;

public class Test {

	public static void main(String[] args) {
		/**
		 * 
		 *  "port": 1, 
            "name": "射灯", 
            "type": "Light", 
            "room": 1, 
            "coutDown": 15, 
            "maxON": 0, 
            "hide": 0, 
            "isFeedback": true, 
            "sequence_all": 2, 
            "sequence_room": 3
		 */
		DeviceEntity deEntity1=new DeviceEntity();
		deEntity1.setPort(1);
		deEntity1.setName("射灯");
		deEntity1.setType("Light");
		deEntity1.setRoom(1);
		deEntity1.setCoutDown(15);
		deEntity1.setMaxON(0);
		deEntity1.setHide(0);
		deEntity1.setIsFeedback(true);
		deEntity1.setSequence_all(2);
		deEntity1.setSequence_room(3);
		
		DeviceEntity deEntity2=new DeviceEntity();
		deEntity2.setPort(2);
		deEntity2.setName("灯");
		deEntity2.setType("Light");
		deEntity2.setRoom(1);
		deEntity2.setCoutDown(15);
		deEntity2.setMaxON(0);
		deEntity2.setHide(0);
		deEntity2.setIsFeedback(true);
		deEntity2.setSequence_all(2);
		deEntity2.setSequence_room(3);
		
		DeviceDto deviceDto=new DeviceDto();
		deviceDto.setMac("10-10-10-10");
		deviceDto.setChannel(0);
		deviceDto.setCmd(1001);
		deviceDto.setIsSub(true);
		
		List<DeviceEntity> list=new ArrayList<DeviceEntity>();
		list.add(deEntity2);
		list.add(deEntity1);
		
		deviceDto.setDevices(list);
		
		String b=JSONObject.toJSONString(deviceDto);
		System.out.println(b);
		
		JSONObject c=JSONObject.parseObject(b);
		String d=c.getString("devices");
		System.out.println(d);
		List<DeviceEntity> deviceEntity3 = (List) JsonUtils.getBeans(
				 d, DeviceEntity.class);
		for(DeviceEntity e : deviceEntity3){
			
			System.out.println(e.getName());
		}
		
		
		
		
		
		
	}

}
